<template>
  <div class="collectslide" @touchmove.stop="stopKove">
    <div class="head">
      <p class="recommend">推荐创作人</p>
      <span class="more">查看更多 ></span>
    </div>
    <div class="itembox">
      <div class="item" @click="onClick(i.model.resource.id)" v-for="(i, index) in item" :key="index">
        <img :src="i.model.resource.avatar" alt="" />
        <p class="username">{{ i.model.resource.username }}</p>
        <p class="count">
          {{ i.model.resource.count.count_article }} 作品 ·
          {{ i.model.resource.count.count_follower }} 粉丝
        </p>
        <p class="role">{{ i.model.resource.occupation }}</p>
        <div class="guanzhu guanzhued" v-if="attentionList.indexOf(i.model.resource.id)!=-1" @click.stop="attention(i.model.resource.id)">已关注</div>
        <div class="guanzhu" v-else @click.stop="attention(i.model.resource.id)">+ 关注</div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  props: {
    item: Array,
  },
  methods:{
    attention(id){
      this.$store.commit('addAttention',{id:id})
    },
    stopKove(){
      return false
    },
    onClick(id){
      this.$router.push({path:"/userpage",query:{id:id}})
    }
  },
  computed:{
    ...mapState(["attentionList"])
  }
};
</script>

<style lang="less" scoped>
.collectslide {
  width: 100%;
  height: 100%;
  .head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .recommend {
      font-size: 18px;
      font-weight: 600;
      color: #000;
    }
    .more {
      font-size: 14px;
      color: #888;
    }
    margin-bottom: 10px;
  }
  .itembox {
    display: flex;
    overflow-x: auto;
    &::-webkit-scrollbar {
      display: none;
    }
    .item {
      flex-shrink: 0;
      width: 160px;
      height: 190px;
      background-color: #fff;
      border-radius: 10px;
      overflow: hidden;
      display: flex;
      flex-wrap: wrap;
      flex-direction: column;
      align-items: center;
      justify-content: space-around;
      padding: 10px;
      margin-right: 10px;
      img {
        flex-shrink: 0;
        width: 40px;
        height: 40px;
        border-radius: 50%;
      }
      .username {
        font-weight: 600;
      }
      .count {
        font-size: 12px;
        color: #aaa;
      }
      .role {
        font-size: 12px;
        color: #aaa;
      }
      .guanzhu {
        width: 80px;
        height: 30px;
        border-radius: 30px;
        color: white;
        background-color: red;
        display: flex;
        align-items: center;
        justify-content: center;
        &.guanzhued{
          background-color: #ddd;
          color: #888;
        }
      }
    }
  }
}
</style>